﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TimeManager : MonoBehaviour {


    private Text _time;
    private float _timer=0;
    // Use this for initialization
    void Start()
    {
        _time = transform.GetComponent<Text>();
    }
    private void Update()
    {
        _timer += Time.deltaTime;
        NowTime(_timer);
        _time.text = "Time:" + NowTime(_timer);
    }
  
    public void ChangeTime(float scale)
    {
        if (_timer < 5)
        {
            _timer = 0;
        }
        else
        {
            _timer -= scale;
        }
    }
   

    public void Initalize()
    {
        _timer = 0f;


    }
   
    string NowTime(float time)
    {


        //Time.time 游戏从开始到现在所用的时间秒为单位
        string timeAfter = NowTimeHour(time) + ":" + NowTimeMin(time) + ":" + NowTimeSecond(time);
        return timeAfter;

    }

    private string NowTimeSecond(float time)
    {

        string Second = null;

        int number = (int)(time % 60);

        if (number < 10)
        {

            Second = "0" + number.ToString();

        }
        else
        {

            Second = number.ToString();

        }

        return Second;

    }

    string NowTimeMin(float time)
    {

        string Min = null;

        int number = (int)(time / 60);

        if (number < 10)
        {

            Min = "0" + number.ToString();

        }
        else
        {

            Min = number.ToString();

        }

        return Min;

    }
    string NowTimeHour(float time)
    {

        string Hour;

        int number = (int)(time / 3600);

        if (number < 10)
        {
            Hour = "0" + number.ToString();

        }
        else
        {

            Hour = number.ToString();

        }

        return Hour;

    }
}
